Skip to main content

Single Number

Question

Given a non-empty array of integers, every element appears twice except for one. Find that single one.

Example 1


Input: [2,2,1]
Output: 1

Solution

all//Single Number.py


def singleNumber(nums):
single = 0
for num in nums:
single ^= num
return single